export default {
  data() {
    return {
      siftName: '',
      current: 1,
      dataList: [],
      total: 0,
      loadMore: 'loadmore',
      contentHeight: 0
    }
  },
  watch: {
    dataList(val) {
      if(this.total <= this.dataList.length) {
        this.loadMore = 'nomore'
      }
    }
  },
  mounted() {
    const dom = uni.createSelectorQuery().in(this).select('.content')
    dom.boundingClientRect((info) => {
      this.contentHeight = info.height
      this.multipleSize = (info.width - 60) / 3
    }).exec()
  },
  methods: {
    onRefresh(current, size) {
      this.current = current
      this.getDataList(true)
    },
    onLoadMore() {
      if(!this.isRequest) {
        this.isRequest = true
        this.current++
        this.getDataList(false)
      }
    },
    onScroll(e) {
      const { deltaY, scrollTop, scrollHeight } = e.target
      if(deltaY < 0 && scrollHeight - this.contentHeight - scrollTop < 50 && this.loadMore == 'loadmore') {  //向下滑动
        this.timer && clearTimeout(this.timer)
        this.timer = setTimeout(() => {
          this.loadMore = 'loading'
          this.onLoadMore()
        }, 300);
      }
    }
  },
}